package leetcodecompetition.S116;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: Siantar
 * @Date: 2023-10-28-22:44
 * @Description: 1.0
 */
public class T100042 {
    public int lengthOfLongestSubsequence(List<Integer> nums, int target) {
        int[] ps = new int[target + 1];
        nums.sort((a, b) -> a - b);
        for (int i : nums) {
            System.out.println(i);
            int[] ns = new int[target + 1];
            ns[i]=1;
            for (int j = 1; j <= target; j++) {
                if (ps[j] > 0 && i + j <= target) {
                    System.out.println(" " + j);
                    ns[i + j] = ps[j] + 1;
                    System.out.println(i+j+"="+ns[i + j]);
                }
            }
            for (int j = 0; j <=target ; j++) {
                ps[i]=Math.max(ps[i],ns[i]);
            }
            ps = ns;
            for (int j = 0; j < ps.length; j++) {
                System.out.print(ps[j]+" ");
            }
            System.out.println();
        }
        return ps[target] == 0 ? -1 : ps[target];
    }
}
